package com.admxj.mybatis.demo.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author jin.xiang
 * @version Id: JdbcDemo, v 0.1 2020/6/1 12:56 下午 jin.xiang Exp $
 */
public class JdbcDemo {

  public static void main(String[] args) throws SQLException {


    Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test", "root", "123456");

    PreparedStatement preparedStatement = connection.prepareStatement("select id, dep_city, arr_city, status, version, env from switch where dep_city=? AND status = ?");

    preparedStatement.setString(1, "SHA");
    preparedStatement.setInt(2, 1);

    ResultSet resultSet = preparedStatement.executeQuery();

    System.out.println("id\tdep_city\tarr_city\tstatus\tversion\tenv");
    while (resultSet.next()) {
      System.out.print(resultSet.getString(1) + "\t");
      System.out.print(resultSet.getString(2) + "\t");
      System.out.print(resultSet.getString(3) + "\t");
      System.out.print(resultSet.getString(4) + "\t");
      System.out.println(resultSet.getString(5) + "\t");
    }

    resultSet.close();
    preparedStatement.close();
    connection.close();

  }

}
